//
//  NetworkStatusMonitorManager.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/30.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "NetworkStatusMonitorManager.h"

NSString *const NetworkReachabilityStatusChangedNotification = @"NetworkReachabilityStatusChangedNotification";

@implementation NetworkStatusMonitorManager

static NetworkStatusMonitorManager *_networkStatusMonitorManager = nil;
+ (instancetype)sharedMonitor {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _networkStatusMonitorManager = [[NetworkStatusMonitorManager alloc] init];
    });
    return _networkStatusMonitorManager;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        _reachabilityManager = [AFNetworkReachabilityManager sharedManager];
        [self monitoringAction];
    }
    return self;
}
- (void)monitoringAction {
    __weak typeof(self) wself = self;
    [self.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
                
                break;
            case AFNetworkReachabilityStatusNotReachable:
                
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                
                break;
            default:
                break;
        }
        //post notification
        [[NSNotificationCenter defaultCenter] postNotificationName:NetworkReachabilityStatusChangedNotification object:nil];
    }];
}


/**
 Starts monitoring for changes in network reachability status.
 */
- (void)startMonitoring {
    [self.reachabilityManager startMonitoring];
}

/**
 Stops monitoring for changes in network reachability status.
 */
- (void)stopMonitoring {
    [self.reachabilityManager stopMonitoring];
}
@end
